class LearnCourseDetailRows {
  int ret;
  LearnCourseRowsData data;
  String msg;

  LearnCourseDetailRows({this.ret, this.data, this.msg});

  LearnCourseDetailRows.fromJson(Map<String, dynamic> json) {
    ret = json['ret'];
    msg = json['msg'];
    data = json['data'] != null ? new LearnCourseRowsData.fromJson(json['data']) : null;
  }

}

class LearnCourseRowsData {
  int total;
  List<LearnCourseDetailEntity> rows;

  LearnCourseRowsData({this.total, this.rows});

  LearnCourseRowsData.fromJson(Map<String, dynamic> json) {
    total = json['total'];
    if (json['rows'] != null) {
      rows = new List<LearnCourseDetailEntity>();
      json['rows'].forEach((v) {
        rows.add(new LearnCourseDetailEntity.fromJson(v));
      });
    }
  }

}

///学习课程详情
class LearnCourseDetailEntity {
  ///购买的总课时
  int courseNum;
  ///已学课时
  int finishedNum;
  ///商品名称
  String className;
  String kemu;
  /// 加入后的主键
  int mainId;
  String teacherPic;
  String teacher;
  /// 日期 07-18
  String startDate;
  String endDate;

  LearnCourseDetailEntity({
    this.courseNum,
    this.finishedNum,
    this.className,
    this.kemu,
    this.mainId,
    this.teacherPic,
    this.teacher,
    this.startDate,
    this.endDate
  });

  LearnCourseDetailEntity.fromJson(Map<String, dynamic> json) {
    //字段值 = 班课字段 ?? 一对一字段

    //用户购买的课时数还能是小数 ？？ 日 ！！！
    var buyCount = json['BUY_HOUR'] ?? json['BUY_CLASS_NUM'];
    courseNum = buyCount is double ? buyCount.toInt() : buyCount;
    finishedNum = json['KX_HOUR'] ?? json['USED_CLASS_NUM'];
    className = json['CLASS_NAME'];
    kemu = json['PRODUCT_COURSE'] ?? json['KEMU'];
    mainId = json['PK_STU_CLASS'];
    teacherPic = json['TEA_PIC'] ?? json['PIC'];
    teacher = json['TEACHER_NAME'] ?? json['TEACHER'];
    startDate = json['START_DATE'];
    endDate = json['END_DATE'];
  }


  String getSubDesc() {
    String desc = '';
    if (startDate != null && endDate != null) {
      desc = '$startDate 至 $endDate  ';
    }

    if (courseNum != null) {
      desc = '$desc共$courseNum课时';
    }

    return desc;
  }

  /// 进度 0 ~ 1
  double progress() {
    if (finishedNum == null || finishedNum == 0
        || courseNum == null || courseNum == 0) {
      return 0;
    }else {
      return finishedNum / courseNum;
    }
  }

}
